package com.sensePlusVR.utils;

import java.text.DecimalFormat;

public class FileConvertUtil {
	
	public static final int UNIT_ONE = 1;
	public static final int UNIT_TWO = 2;
	
	
	  /** gb to byte **/
    public static final long GB_2_BYTE = 1000*1000*1000;
    /** mb to byte **/
    public static final long MB_2_BYTE = 1000*1000;
    /** kb to byte **/
    public static final long KB_2_BYTE = 1000;
    
    public static String UNIT_CUR_GB = "GB";
    
    public static String UNIT_CUR_MB = "MB";
    
    public static String UNIT_CUR_KB = "KB";
    
    public static String UNIT_CUR_B = "B";
    
    public static final String UNIT_GB = "GB";
    
    public static final String UNIT_MB = "MB";
    
    public static final String UNIT_KB = "KB";
    
    public static final String UNIT_B = "B";
    
    public static final String UNIT_G = "G";
    
    public static final String UNIT_M = "M";
    
    public static final String UNIT_K = "K";
    
    
    public static String getMbGbFileSize(long byteSize){
    	return getMbGbFileSize(byteSize, UNIT_ONE);
    }
    
    public static String getMbGbFileSize(long byteSize,int unitSize){
    	if(unitSize == 1){
    		UNIT_CUR_KB = UNIT_K;
    		UNIT_CUR_MB = UNIT_M;
    		UNIT_CUR_GB = UNIT_G;
    	}else if(unitSize == 2){
    		UNIT_CUR_KB = UNIT_KB;
    		UNIT_CUR_MB = UNIT_MB;
    		UNIT_CUR_GB = UNIT_GB;
    	}
    	 if(byteSize < GB_2_BYTE){
    		return getNumberFormat((float)byteSize / MB_2_BYTE) + UNIT_CUR_MB;
    	}else{
    		return getNumberFormat((float)byteSize / GB_2_BYTE) + UNIT_CUR_GB;
    	}
    
    }
    
    
    public static String getAdaptFileSize(long byteSize){
    	return getAdaptFileSize(byteSize,UNIT_ONE);
    }
    
    /**
     * 
     * @param byteSize 文件 byte大小
     * @return    根据文件大小返回相应KB,MB,GB
     */
    public static String getAdaptFileSize(long byteSize,int unitSize){
    	if(unitSize == 1){
    		UNIT_CUR_KB = UNIT_K;
    		UNIT_CUR_MB = UNIT_M;
    		UNIT_CUR_GB = UNIT_G;
    	}else if(unitSize == 2){
    		UNIT_CUR_KB = UNIT_KB;
    		UNIT_CUR_MB = UNIT_MB;
    		UNIT_CUR_GB = UNIT_GB;
    	}
    	if(byteSize < KB_2_BYTE){
    		return getNumberFormat(byteSize) + UNIT_CUR_B;
    	}else if(byteSize < MB_2_BYTE){
    		return getNumberFormat((float)byteSize / KB_2_BYTE) + UNIT_CUR_KB;
    	}else if(byteSize < GB_2_BYTE){
    		return getNumberFormat((float)byteSize / MB_2_BYTE) + UNIT_CUR_MB;
    	}else{
    		return getNumberFormat((float)byteSize / GB_2_BYTE) + UNIT_CUR_GB;
    	}
    }
    
    
    
    private static String getNumberFormat(float byteSize){
    	//#表示没有则为空，0表示如果没有则该位补0.
    	DecimalFormat decimalFormat = new DecimalFormat("0.0");
    	return decimalFormat.format(byteSize);
    	
    }

}
